package com.lp.biz.train.controller;

import com.lp.biz.train.model.query.*;
import com.lp.biz.train.model.vo.*;
import com.lp.biz.train.service.BizTrainClassService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.CONTENT_CLASS;
import static com.lp.common.constant.RoleConstant.CLASS_TEACHER;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-05-23 21:32:33
 */
@RestController
@RequestMapping("/classes")
public class BizTrainClassController {

    @Autowired
    private BizTrainClassService classService;

    /**
     * 班主任获取班级列表
     * @return 查询列表
     */
    @GetMapping("")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getClasses(PageParams query) {
        return classService.getClasses(query);
    }

    /**
     * 获取班级详情
     * @param classId 班级Id
     * @return 查询结果
     */
    @GetMapping("/{classId}")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getClassDetail(@PathVariable Integer classId) {
        return classService.getClassDetail(classId);
    }

    /**
     * 更新班级开始结束时间
     * @param classId 班级id
     * @param params 时间参数
     * @return 处理结果
     */
    @PutMapping("/{classId}")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult updateClassDate(@PathVariable Integer classId, @RequestBody@Validated ClassUpdateDate params) {
        classService.updateClassDate(classId, params);
        return CommonResult.success();
    }

    /**
     * 删除班级
     * @param classId 班级id
     * @return 处理结果
     */
    @DeleteMapping("/{classId}")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult deleteClass(@PathVariable Integer classId) {
        classService.deleteClass(classId);
        return CommonResult.success();
    }

    /**
     * 获取班级章节
     * @param classId 班级id
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/chapter")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getClassChapter(@PathVariable Integer classId, ClassChapterQuery query) {
        return classService.getClassChapter(classId, query);
    }

    /**
     * 发布章节
     * @param classId 班级id
     * @param chapterId 章节id
     * @return 处理结果
     */
    @PutMapping("/{classId}/chapter/{chapterId}/publish")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult publishChapter(@PathVariable Integer classId, @PathVariable Integer chapterId) {
        classService.publishChapter(classId, chapterId);
        return CommonResult.success();
    }

    /**
     * 获取班级用户列表
     * @param classId 班级id
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/member")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getClassMemberList(@PathVariable Integer classId, ClassMemberQuery query) {
        return classService.getClassMemberList(classId, query);
    }

    /**
     * 获取班级助教/导师
     * @param classId 班级id
     * @return 查询结果
     */
    @GetMapping("/{classId}/manage")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getClassManage(@PathVariable Integer classId) {
        return classService.getClassManage(classId);
    }

    /**
     * 班级学员转移归属
     * @param classId 班级id
     * @param assignMember 学员列表
     * @return 处理结果
     */
    @PostMapping("/{classId}/assign")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult assignToManager(@PathVariable Integer classId, @RequestBody@Validated ClassAssignMember assignMember) {
        classService.assignToManager(classId, assignMember);
        return CommonResult.success();
    }

    /**
     * 获取班级作业
     *
     * @param classId 班级id
     * @param query 分页参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/homeworks")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getClassHomeworks(@PathVariable Integer classId, PageParams query) {
        return classService.getClassHomeworks(classId, query);
    }

    /**
     * 发布班级作业
     * @param homeworkId 作业id
     * @return 处理结果
     */
    @PutMapping("/{classId}/homeworks/{homeworkId}/publish")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult publishClassHomework(@PathVariable Integer classId, @PathVariable Integer homeworkId) {
        classService.publishClassHomework(classId, homeworkId);
        return CommonResult.success();
    }

    /**
     * 获取班级已提交作业列表
     * @param classId 班级id
     * @param query 分页参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/homeworks/submitted")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult submittedComment(@PathVariable Integer classId, SubmittedHomeworkQuery query) {
        return classService.submittedComment(classId, query);
    }

    /**
     * 班级作业置顶/取消置顶
     * @param classId 班级id
     * @param commentId 打卡id
     * @return 处理结果
     */
    @PutMapping("/{classId}/comments/{commentId}/top")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult commentTop(@PathVariable Integer classId, @PathVariable Integer commentId) {
        classService.commentTop(classId, commentId);
        return CommonResult.success();
    }

    /**
     * 删除班级作业
     * @param classId 班级id
     * @param commentId 作业id
     * @return 处理结果
     */
    @DeleteMapping("/{classId}/comments/{commentId}")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult deleteComment(@PathVariable Integer classId, @PathVariable Integer commentId) {
        classService.deleteComment(classId, commentId);
        return CommonResult.success();
    }

    /**
     * 获取班级未提交的作业列表
     * @param classId 班级id
     * @return 查询结果
     */
    @GetMapping("/{classId}/homeworks/unsubmitted")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult unsubmittedComment(@PathVariable Integer classId, SubmittedHomeworkQuery query) {
        return classService.unsubmittedComment(classId, query);
    }

    /**
     * 打卡增加点评
     * @param classId 班级id
     * @param commentId 打卡id
     * @param addComment 点评参数
     * @return 处理结果
     */
    @PostMapping("/{classId}/comments/{commentId}")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult addComment(@PathVariable Integer classId, @PathVariable Integer commentId, @RequestBody@Validated ClassAddComment addComment) {
        classService.addComment(classId, commentId, addComment);
        return CommonResult.success();
    }

    /**
     * 获取打卡内容详情
     * @param classId 班级id
     * @param commentId 打卡id
     * @return 查询结果
     */
    @GetMapping("/{classId}/comments/{commentId}")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getComment(@PathVariable Integer classId, @PathVariable Integer commentId) {
        return classService.getComment(classId, commentId);
    }

    /**
     * 获取班级下的所有活动
     * @param classId 班级id
     * @param query 分页参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/events")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getEvents(@PathVariable Integer classId, PageParams query) {
        return classService.getEvents(classId, query);
    }

    /**
     * 创建活动
     * @param classEventsCreate 活动参数
     * @param classId 班级id
     * @return 处理结果
     */
    @PostMapping("/{classId}/events")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult addEvents(@RequestBody @Validated ClassEventsCreate classEventsCreate,
                                  @PathVariable Integer classId) {
        classService.addEvents(classEventsCreate, classId);
        return CommonResult.success();
    }

    /**
     * 获取班级报名人员列表
     * @param classId 班级id
     * @param eventId 活动id
     * @return 查询结果
     */
    @GetMapping("/{classId}/events/{eventId}/sign-up")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getEventSignUp(@PathVariable Integer classId, @PathVariable Integer eventId, PageParams query) {
        return classService.getEventSignUp(classId, eventId, query);
    }

    /**
     * 设置活动主持人
     * @param classId 班级id
     * @param eventId 活动id
     * @param moderator 主持人
     * @return 处理结果
     */
    @PutMapping("/{classId}/events/{eventId}/moderator")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult updateModerator(@PathVariable Integer classId, @PathVariable Integer eventId,
                                        @RequestBody@Validated ClassModerator moderator) {
        classService.updateModerator(classId, eventId, moderator);
        return CommonResult.success();
    }

    /**
     * 获取班级未报名人员列表
     * @param classId 班级id
     * @param eventId 活动id
     * @param query 分页参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/events/{eventId}/not-enrolled")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getNotEnrolled(@PathVariable Integer classId, @PathVariable Integer eventId, PageParams query) {
        return classService.getNotEnrolled(classId, eventId, query);
    }

    /**
     * 班级创建投票
     * @param classId 班级id
     * @param classVote 投片参数
     * @return 处理结果
     */
    @PutMapping("/{classId}/vote")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult startVote(@PathVariable Integer classId, @RequestBody@Validated ClassVoteCreate classVote) {
        classService.startVote(classId, classVote);
        return CommonResult.success();
    }

    /**
     * 获取班级投票详情
     * @param classId 班级id
     * @return 查询结果
     */
    @GetMapping("/{classId}/vote")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getVoteDetail(@PathVariable Integer classId) {
        return classService.getVoteDetail(classId);
    }

    /**
     * 获取投票列表
     * @param classId 班级id
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/vote/members")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getVoteMembers(@PathVariable Integer classId, ClassVoteMembersQuery query) {
        return classService.getVoteMembers(classId, query);
    }

    /**
     * 获取结营证书列表
     *
     * @param classId 班级id
     * @param query   查询参数
     * @return 查询结果
     */
    @GetMapping("/{classId}/graduation")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getGraduationList(@PathVariable Integer classId, ClassGraduationQuery query) {
        query.setClassId(classId);
        return classService.getGraduationList(query);
    }

    /**
     * 获取所有活动类型
     * @return 查询结果
     */
    @GetMapping("/task/type")
    @PermissionAnnotation(menus = {CONTENT_CLASS}, roles = {CLASS_TEACHER})
    public CommonResult getTaskType() {
        return classService.getTaskType();
    }

}
